<template>
  <div
    class="item-container tech-need-container cursor-pointer"
    @click="toDetail"
  >
    <div class="title">{{ objInfo.title }}</div>
    <p class="content" v-html="objInfo.content"></p>
    <ul class="info-list">
      <li>
        <span class="label"> 发布时间: </span>
        {{ objInfo.publishTime }}
      </li>

      <li>
        <span class="label"> 所属领域: </span>
        {{ filedDictName(objInfo.fieldId) }}
      </li>

      <li>
        <span class="label"> 需求类型: </span>
        {{ techNeedName(objInfo.typeId) }}
      </li>

      <li>
        <span class="label"> 所在地: </span>
        {{ objInfo.location }}
      </li>
    </ul>
    <div
      class="right rounded-md py-2 bg-yellow-500 text-xl text-white text-center "
    >
      {{ statusText(objInfo.status) }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'TechNeedItem',
  props: {
    objInfo: {
      type: Object,
      default: () => {
        return {
          picture: '',
          title: '',
          fieldId: '',
          typeId: '',
          location: '',
          content: '',
          publishTime: '',
          status: '',
        }
      },
    },
  },
  data() {
    return {
      techNeedDictName: 'requirement_demand_type',
      techNeedDictList: [],

      positionDictName: 'user_common_field',
      positionList: [],

      detailRouteName: '/techSource/techNeed/techNeedDetail/',
    }
  },
  computed: {
    statusColor() {
      return (status) => {
        let res = ''
        switch (status) {
          case 1:
            res = '#959595'
            break
          case 0:
            res = '#f92b00'
            break
          default:
            res = '#f92b00'
            break
        }
        return res
      }
    },
    statusText() {
      return (status) => {
        status = parseInt(status)
        let res = ''
        switch (status) {
          case 1:
            res = '已揭榜'
            break
          case 0:
            res = '未揭榜'
            break
          default:
            res = '未揭榜'
            break
        }
        return res
      }
    },
    techNeedName() {
      return (fileValue) => {
        let findItem = {}
        findItem = this.techNeedDictList.find(
          (item) => parseInt(item.dictValue) === parseInt(fileValue)
        )
        if (findItem) {
          return findItem['dictLabel'] ? findItem['dictLabel'] : '无'
        }
        return '无'
      }
    },
    filedDictName() {
      return (fileValue) => {
        let findItem = {}
        findItem = this.positionList.find(
          (item) => parseInt(item.dictValue) === parseInt(fileValue)
        )
        if (findItem) {
          return findItem['dictLabel'] ? findItem['dictLabel'] : '无'
        }
        return '无'
      }
    },
  },
  created() {
    this.initDictList()
  },
  methods: {
    initDictList() {
      this.getDictList(this.techNeedDictName).then((res) => {
        if (res.code == 200) {
          this.techNeedDictList = res.data
        }
      })

      this.getDictList(this.positionDictName).then((res) => {
        if (res.code == 200) {
          this.positionList = res.data
        }
      })
    },
    toDetail() {
      let id = parseInt(this.objInfo.id)
      if (!id && id !== 0) {
        this.$message({
          type: 'error',
          message: '无效id',
        })
        return
      }
      this.$router.push({
        path: this.detailRouteName + id,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.tech-need-container {
  padding: 24px;
  border-radius: 0;
  background-color: #ffffff;
  & > div {
    margin-bottom: 16px;
  }
  .title {
    display: -webkit-box;
    height: 1.5rem;
    max-height: 1.5rem;
    font-size: 16px;
    font-weight: 700;
    color: #333333;
    overflow: hidden;
    text-overflow: -o-ellipsis-lastline;
    text-overflow: ellipsis;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    line-clamp: 1;
  }
  .content {
    display: -webkit-box;
    height: 5.4rem;
    max-height: 5.4rem;
    line-height: 1.8rem;
    overflow: hidden;
    text-overflow: -o-ellipsis-lastline;
    text-overflow: ellipsis;
    color: #666666;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    margin-bottom: 24px;
  }
  .info-list {
    list-style: none;
    font-size: 14px;
    font-family: Source Han Sans CN, Source Han Sans CN-Regular;
    font-weight: 400;
    color: #999999;
    margin-bottom: 30px;
    li {
      height: 1.7rem;
      line-height: 1.7rem;

      span {
        display: inline-block;
      }
    }
    .label {
      min-width: 5rem;
    }
  }

  .el-button {
    width: 100%;
  }
}
</style>
